num = int(input("What is your number? ")) #This statement is an input that is asking the user what number they are choosing.
def fizzbuzz(num): #Defining a function that has a parameter which is num that stands for number in the fizzbuzz, so it contains the main functions of the program.
if num % 3 == 0 and num % 5 == 0: #This is an if statement that is showing if num % 3 is 0 and if num % 5 is 0 too then it will be FizzBuzz, so the number is put into this option to see if it is true.
print("Fizzbuzz") #This is a print statement that shows the user that their number is FizzBuzz so when num % 3 and 5 it is = 0.
elif num % 3 == 0: #This is an elif statement that shows as another option, so if the statement above is false then it puts num % 3 = 0 if it is true.
print("Fizz") #This is a print statement that shows the user if the statement above is true that it is only Fizz.
elif num % 5 == 0: #This is an elif statement that runs if the statements above are false, which shows that if num % 5 is = 0 then it will print the statement below.
print("Buzz") #This is a print statement that shows the number is Buzz.
else: #This statement runs when the other if and elif statements are not true.
strings = str(num) #This statement is changing the num to a string and making it equal to the variable, strings.
print(strings) #This is a print statement that is printing the string, which is the number converted to a string.
fizzbuzz(num) #This is a statement that calls the function, so it will run and the main functions of the program will be executed.
while True: #This is a while loop, so it will keep running in order to ask the user if they want to run the program again.
goagain = input("Do you want to play the FizzBuzz Program again? ") #This is an input, which is asking the user if they want to go again.
if goagain.lower() == "yes": #This is an if statement that shows if they do want to play the program again then the statement below will run.
num = int(input("What is your number? ")) #This is will only run if the user's choice is yes, so it will ask what number they choose again.
fizzbuzz(num) #This will call the function so the game will run
else: #This statement is true when the if statement above is false.
print("Have a good day!") #This is a print statement that shows the user that the program has ended and it tells them to have a good day.
break #This will end the while loop
What is your number? 3 Fizz Do you want to play the FizzBuzz Program again? yes What is your number? 15 Fizzbuzz Do you want to play the FizzBuzz Program again? yes What is your number? 21 Fizz Do you want to play the FizzBuzz Program again? yes What is your number? 5 Buzz Do you want to play the FizzBuzz Program again? yes What is your number? 11 11 Do you want to play the FizzBuzz Program again? no Have a good day!